package 多线程进阶;

import java.util.concurrent.Executors;

/**
 * 循环等待锁
 */
public class TestDemo6 {
    public static void main(String[] args) {
        Object locker1=new Object();
        Object locker2=new Object();
        Thread threadA=new Thread(()->{
            synchronized (locker1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker2){
                    System.out.println("threadA is Run");
                }
            }
        });
        Thread threadB=new Thread(()->{
            synchronized (locker2){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker1){
                    System.out.println("threadB is Run");
                }
            }
        });
        threadA.start();
        threadB.start();
        /**
         *        如果threadA拿到了locker1，threadB拿到了locker2
         *        threadA在等待threadB释放locker2，而threadB在的等待threadA释放locker1
         *        这样就形成了一个你不让我，我不让你的局势，然后就陷入了循环等待锁了
         */
    }
}
